/**
 * 生成时间
 * @param formatStr
 * @param fdate
 * @returns {string|string}
 */
function getDate(formatStr, fdate){
    var fTime, fStr = 'ymdhis';
    if (!formatStr)
        formatStr= "y-m-d h:i:s";
    if (fdate)
        fTime = new Date(fdate);
    else
        fTime = new Date();
    var formatArr = [
        fTime.getFullYear().toString(),
        (fTime.getMonth()+1).toString(),
        fTime.getDate().toString(),
        fTime.getHours().toString(),
        fTime.getMinutes().toString(),
        fTime.getSeconds().toString()
    ];
    for (var i=0; i<formatArr.length; i++){
        formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
    }
    return formatStr;
}

/**
 * 获取时间
 * @returns {string}
 */
function yndhis(){
    return getDate('y-m-d h:i:s',new Date())
}

function time(){
    return Date.parse(new Date())/1000;
}

/**
 * 时间转时间戳
 * @param time
 * @returns {number}
 */
function getTime(time){
    return new Date(time).valueOf();
}

module.exports = {
    getDate,
    yndhis,
    getTime,
    time
};